package com.compunit.composite;

import java.util.Properties;

import org.compunit.Provide;
import org.compunit.interfaces.IComponent;
import org.compunit.interfaces.IResourceRetriever;
import org.lwjgl.opengl.GL11;

import com.compunit.composite.b.interfaces.IUpdater;

@Provide({IUpdater.class})
public class Updater implements IUpdater {
	
	private float angle;
	private float speed;

	@Override
	public void update(float interpolation) {
		this.angle += interpolation/10000000.0f * this.speed;
		// Reset matrix.
		GL11.glLoadIdentity();
		// Move object into screen by 5 since we are in model view mode.
		GL11.glTranslatef(0, 0, -5f);
		// Rotate.
		GL11.glRotatef(this.angle, 1, 0, 1);
	}

	@Override
	public void customize(final Properties properties) throws Exception {
		this.speed = Float.valueOf(properties.getProperty("speed", "1"));
	}

	@Override
	public boolean activate(final IResourceRetriever handler) throws Exception {
		return true;
	}

	@Override
	public boolean connect(final IComponent unit, final String interfaceName) throws Exception {
		return true;
	}

	@Override
	public void deactivate() throws Exception {}
}
